package com.agilya.modele;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import com.agilya.enumere.NiveauDifficulte;

public class Question {

	private int id;
	private String libelle;
	private NiveauDifficulte niveauDifficulte;
	private double coefficient;
	private boolean estActif;
	private Date dateCreation;
	private int version;
	private List<Proposition> listePropositions;

	/**
	 * @param id
	 * @param libelle
	 * @param niveauDifficulte
	 * @param coefficient
	 * @param estActif
	 * @param dateCreation
	 * @param version
	 * @param listePropositions
	 */
	public Question(int id, String libelle, NiveauDifficulte niveauDifficulte, double coefficient, boolean estActif, Date dateCreation, int version, List<Proposition> listePropositions) {
		this.id = id;
		this.libelle = libelle;
		this.niveauDifficulte = niveauDifficulte;
		this.coefficient = coefficient;
		this.estActif = estActif;
		this.dateCreation = dateCreation;
		this.version = version;
		this.listePropositions = listePropositions;
	}

	/**
	 * 
	 * @param id
	 * @param libelle
	 * @param niveauDifficulte
	 * @param coefficient
	 * @param estActif
	 * @param dateCreation
	 * @param version
	 */
	public Question(int id, String libelle, NiveauDifficulte niveauDifficulte, double coefficient, boolean estActif, Date dateCreation, int version) {
		this(id, libelle, niveauDifficulte, coefficient, estActif, dateCreation, version, null);
	}

	/**
	 * 
	 * @param libelle
	 * @param niveauDifficulte
	 * @param coefficient
	 */
	// constructeur pour la saisie de questions
	public Question(String libelle, NiveauDifficulte niveauDifficulte, double coefficient) {
		this.libelle = libelle;
		this.niveauDifficulte = niveauDifficulte;
		this.coefficient = coefficient;
		this.estActif = false;
		this.dateCreation = new Timestamp(new java.util.Date().getTime());
		this.version = 0;
		this.listePropositions = null;
	}

	/**
	 * @return the libelle
	 */
	public String getLibelle() {
		return libelle;
	}

	/**
	 * @param libelle
	 *            the libelle to set
	 */
	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}

	/**
	 * @return the niveauDifficulte
	 */
	public NiveauDifficulte getNiveauDifficulte() {
		return niveauDifficulte;
	}

	/**
	 * @param niveauDifficulte
	 *            the niveauDifficulte to set
	 */
	public void setNiveauDifficulte(NiveauDifficulte niveauDifficulte) {
		this.niveauDifficulte = niveauDifficulte;
	}

	/**
	 * @return the coefficient
	 */
	public double getCoefficient() {
		return coefficient;
	}

	/**
	 * @param coefficient
	 *            the coefficient to set
	 */
	public void setCoefficient(double coefficient) {
		this.coefficient = coefficient;
	}

	/**
	 * @return the estActif
	 */
	public boolean isEstActif() {
		return estActif;
	}

	/**
	 * @param estActif
	 *            the estActif to set
	 */
	public void setEstActif(boolean estActif) {
		this.estActif = estActif;
	}

	/**
	 * @return the dateCreation
	 */
	public Date getDateCreation() {
		return dateCreation;
	}

	/**
	 * @param dateCreation
	 *            the dateCreation to set
	 */
	public void setDateCreation(Date dateCreation) {
		this.dateCreation = dateCreation;
	}

	/**
	 * @return the version
	 */
	public int getVersion() {
		return version;
	}

	/**
	 * @param version
	 *            the version to set
	 */
	public void setVersion(int version) {
		this.version = version;
	}

	/**
	 * @return the listePropositions
	 */
	public List<Proposition> getListePropositions() {
		return listePropositions;
	}

	/**
	 * @param listePropositions
	 *            the listePropositions to set
	 */
	public void setListePropositions(List<Proposition> listePropositions) {
		this.listePropositions = listePropositions;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * retourne si la proposition est contenue dans la question
	 * 
	 * @param proposition
	 * @return true si la proposition est inclue, sinon false.
	 */
	public boolean containsProposition(Proposition proposition) {
		return listePropositions.contains(proposition);
	}

	/**
	 * calcule la note maximale pour une question
	 * 
	 * @return la note maximale
	 */
	public double calculerNoteMax() {
		double coefProposition;
		double noteMax = 0;

		coefProposition = 0;
		for (Proposition proposition : listePropositions) {
			if (proposition.estCorrecte())
				coefProposition += proposition.getCoefficient();
		}

		noteMax += coefficient * coefProposition;

		return noteMax;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {

		if (this.getClass() == obj.getClass() && this.id == ((Question) obj).getId()) {
			return true;
		} else {
			return false;
		}
	}

}
